import 'package:flutter/material.dart';
import 'package:flowerny/model/messon.dart';

class MessionItem extends StatelessWidget {
  final Mession mession;

  MessionItem({Key key, this.mession, this.onPressed}) : super(key: key);
  VoidCallback onPressed;

  @override
  Widget build(BuildContext context) {
    Color _typeColor = Colors.cyan[300];
    switch (mession.m_type) {
      case 1:
        _typeColor = Colors.cyan.shade200;
        break;
      case 2:
        _typeColor = Colors.amberAccent.shade200;
        break;
      case 3:
        _typeColor = Colors.greenAccent[200];
        break;
      case 4:
        _typeColor = Colors.redAccent[100];
        break;
    }
    return new GestureDetector(
      onTap: onPressed,
      child: new Container(
        height: 78.0,
        margin: const EdgeInsets.only(top: 5.0, bottom: 5.0),
        color: Colors.white,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Container(
              padding: const EdgeInsets.only(
                  left: 12.0, top: 10.0, right: 5.0, bottom: 10.0),
              child: CircleAvatar(
                backgroundImage: NetworkImage(mession.m_icon),
                radius: 26.0,
                backgroundColor: Colors.white,
              ),
            ),
            Expanded(
                child: Container(
              padding: const EdgeInsets.only(top: 5.0, right: 5.0),
              alignment: Alignment.centerLeft,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Container(
                      margin: const EdgeInsets.only(bottom: 5.0),
                      child: Row(children: <Widget>[
                        Text(
                          mession.m_name,
                          style:
                              new TextStyle(color: Colors.black, fontSize: 16),
                        ),
                        Container(
                          decoration: new BoxDecoration(
                            color: new Color(0xFFF6F6F8),
                            borderRadius:
                                new BorderRadius.all(new Radius.circular(6.0)),
                          ),
                          padding: const EdgeInsets.only(
                              top: 3.0, bottom: 3.0, left: 8.0, right: 8.0),
                          margin: const EdgeInsets.only(left: 15.0),
                          child: Text(
                            mession.m_type_name,
                            style: new TextStyle(
                                color: Color.fromARGB(255, 0, 215, 198),
                                fontSize: 12),
                          ),
                        ),
                      ])),
                  Text(
                    mession.m_slogen,
                    overflow: TextOverflow.ellipsis,
                    maxLines: 2,
                    style: new TextStyle(
                      color: Colors.grey[400],
                      fontSize: 12,
                    ),
                  ),
                ],
              ),
            )),
            Container(
              width: 65.0,
              color: _typeColor,
              child: Text(
                '${mession.m_point}分',
                style: new TextStyle(color: Colors.white),
              ),
              alignment: Alignment.center,
            ),
          ],
        ),
      ),
    );
  }
}
